//
//  MK_Content_Cell.m
//  miku直播
//
//  Created by 杨尚达 on 2017/7/23.
//  Copyright © 2017年 杨尚达. All rights reserved.
//

#import "MK_Content_Cell.h"
#import "MK_LivingContent_Cell.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
#import "MK_HorizonShowView.h"

#define MK_Content_Cell_ContenT_Cell @"MK_Content_Cell_ContenT_Cell"

@interface MK_Content_Cell () <UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>

///内容tableView
@property(nonatomic,weak)UITableView* contentT;

///头部轮播视图
@property(nonatomic,strong)SDCycleScrollView* cycView;

///分类滚动视图
@property(nonatomic,strong)MK_HorizonShowView* showHeaderView;

@end

@implementation MK_Content_Cell

-(void)awakeFromNib{
    [super awakeFromNib];
    [self setUpUI];
}

-(void)didMoveToWindow{
    [super didMoveToWindow];
    self.cycView.frame = CGRectMake(0, 0, self.width, self.width*0.4);
    self.showHeaderView.frame = CGRectMake(0, 0, self.width, self.width*0.4);
}

///初始化界面
-(void)setUpUI{
    
    UITableView* contentT = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    [contentT registerNib:[UINib nibWithNibName:@"MK_LivingContent_Cell" bundle:nil] forCellReuseIdentifier:MK_Content_Cell_ContenT_Cell];
    _contentT = contentT;
    _contentT.rowHeight = 263;
    contentT.delegate = self;
    contentT.dataSource = self;
    [self addSubview:contentT];
    [contentT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    contentT.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
    ///图片轮播器
    _cycView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, self.width, self.width*0.3) delegate:self placeholderImage:[UIImage imageNamed:@"default_icon"]];
    _cycView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    
    ///分类轮播器
    _showHeaderView = [MK_HorizonShowView new];
    
    
}

#pragma mark tableView的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.model.livingRoomArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MK_LivingContent_Cell* cell = [tableView dequeueReusableCellWithIdentifier:MK_Content_Cell_ContenT_Cell forIndexPath:indexPath];
    
    cell.model = _model.livingRoomArr[indexPath.row];
    return cell;
}


#pragma mark 接受模型数据
-(void)setModel:(MK_Content_Model *)model{
    _model = model;
    if (model.type == MK_Content_Model_Type_Recommend) {
        _contentT.tableHeaderView = _cycView;
        _cycView.backgroundColor = [UIColor blueColor];
        _cycView.imageURLStringsGroup = _model.slidePicUrlArr;
        _cycView.titlesGroup = _model.slideTitleUrlArr;
        
    }else{
        _contentT.tableHeaderView = _showHeaderView;
        [_showHeaderView reloadDataWithColNum:6 andRowNum:2 andImageUrlArr:model.categoryImageUrlArr andTitleArr:model.categoryTitleName];
    }
    [_contentT reloadData];
}

@end
